package com.liesheng.haylou.ui.personal;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.liesheng.haylou.R;
import com.liesheng.haylou.base.BaseActivity;
import com.liesheng.haylou.base.BaseFunActivity;
import com.liesheng.haylou.base.BaseVm;
import com.liesheng.haylou.databinding.ActivityPersonalCenterBinding;
import com.liesheng.haylou.ui.main.MainActivity;
import com.liesheng.haylou.utils.ImmersiveStatusBarUtil;
import com.liesheng.haylou.utils.ToastUtil;

import androidx.databinding.DataBindingUtil;

/**
 * Created by Android Studio.
 * User: zhangzhiqiang
 * Date: 2019/12/19
 * Time: 17:44
 */
public class PersonalCenterActivity extends BaseActivity<ActivityPersonalCenterBinding, BaseVm> {
    private Dialog tipDialog = null;

    @Override
    protected ActivityPersonalCenterBinding getmBinding() {
        mBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_personal_center, null, false);
        return mBinding;
    }

    @Override
    protected BaseVm getViewModel() {
        return null;
    }

    @Override
    protected void initData() {
        setTitle("我");
        showHeadLayout(false);

        if (ImmersiveStatusBarUtil.supportedImmersiveStatusBar()) {
            LinearLayout.LayoutParams params1 = (LinearLayout.LayoutParams) mBinding.layoutTop.getLayoutParams();
            mBinding.layoutTop.setPadding(0,ImmersiveStatusBarUtil.getStatusBarHeight(),0,0);
        }
    }

    public static void startBy(BaseFunActivity activity) {
        Intent intent = new Intent(activity, PersonalCenterActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected boolean isMarginTop() {
        return false;
    }

    @Override
    public void onClickView(View view) {
        switch (view.getId()) {
            case R.id.head_left:
                finish();
                break;
            case R.id.ivHeader:
                PersonalDataSettingActivity.startBy(PersonalCenterActivity.this);
                break;
            case R.id.ivSportData:
                SportDataActivity.startBy(PersonalCenterActivity.this);
                break;
            case R.id.ivBobyData:
                BobyDataActivity.startBy(PersonalCenterActivity.this);
                break;
            case R.id.photograph:
                break;
            case R.id.photo:
                break;
            case R.id.cancel:
                break;
            case R.id.rlAlterPws:
                AlterPasswordActivity.startBy(PersonalCenterActivity.this);
                break;
//            case R.id.reRight:
//                showTipDialog("退出后，可以重新登录",
//                        () -> logOut());
//                break;
            default:
                break;
        }

    }
    private void logOut() {
        ToastUtil.showToast("退出登陆!");
        MainActivity.startBy(PersonalCenterActivity.this);
    }
    private void showTipDialog(String tips, TipCallBack tipCallBack) {
        tipDialog = new Dialog(PersonalCenterActivity.this, R.style.matchDialog);
        View view = LayoutInflater.from(PersonalCenterActivity.this).inflate(R.layout.tip_dialog_layout, null);
        ((TextView) (view.findViewById(R.id.tips))).setText(tips);
        view.findViewById(R.id.tv_close).setOnClickListener(
                v -> tipDialog.dismiss());
        view.findViewById(R.id.tv_save).setOnClickListener(v -> {
            tipCallBack.confirm();
            tipDialog.dismiss();
        });
        tipDialog.setContentView(view);
        tipDialog.show();
    }
    private interface TipCallBack {
        void confirm();
    }
}
